#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Módulos 
import sys, gtk, pygame, utils, objetos
from pygame.locals import *
# Constantes
 
# Clases
# ---------------------------------------------------------------------
class ObjGrafico(pygame.sprite.Sprite):
    def __init__(self, path, x, y, t=True ):
        pygame.sprite.Sprite.__init__(self)
        self.image = utils.load_image(path, t)
        self.rect = self.image.get_rect()
        self.rect.centerx = x*utils.RES
        self.rect.centery = y*utils.RES


# ---------------------------------------------------------------------
 
# Funciones
# ---------------------------------------------------------------------
 
 
# ---------------------------------------------------------------------
 
def dibujar(screen,cursor_picture, clock):
    	salir = 0
    	background_image = utils.load_image('images/fondo5.png')

    	#boton de la flecha para continuar
    	btn_adelante = objetos.BotonAdelante()
    	btn_atras = objetos.BotonAtras()

    	#texto superior derecho que indica el numero de clase
    	clase2, clase2_rect = utils.texto_clase("Clase 5", 750*utils.RES, 15*utils.RES)
        titulo1, titulo1_rect = utils.textodream("2) ELEGIMOS UN TEMA"    ,    140*utils.RES, 40*utils.RES, 24, color=(255, 0, 0))
        titulo2, titulo2_rect = utils.textodream(".............................",   140*utils.RES, 55*utils.RES, 24, color=(255, 0, 0))    


        temas = utils.load_image('images/clase5_temas.png', True)
	temas_rect = (180,50)

	x,y = (219,93)
	p1a = ObjGrafico('images/pixel.png', x*utils.RES, y*utils.RES, False )
	p1b = ObjGrafico('images/pixel2.png',(x-5)*utils.RES, (y-5)*utils.RES, False )

	x,y = (208,278)
	p2a = ObjGrafico('images/pixel.png', x*utils.RES, y*utils.RES, False )
	p2b = ObjGrafico('images/pixel2.png',(x-5)*utils.RES, (y-5)*utils.RES, False )

	x,y = (380,445)
	p3a = ObjGrafico('images/pixel.png', x*utils.RES, y*utils.RES, False )
	p3b = ObjGrafico('images/pixel2.png',(x-5)*utils.RES, (y-5)*utils.RES, False )

	x,y = (652,308)
	p4a = ObjGrafico('images/pixel.png', x*utils.RES, y*utils.RES, False )
	p4b = ObjGrafico('images/pixel2.png',(x-5)*utils.RES, (y-5)*utils.RES, False )

	x,y = (548,109)
	p5a = ObjGrafico('images/pixel.png', x*utils.RES, y*utils.RES, False )
	p5b = ObjGrafico('images/pixel2.png',(x-5)*utils.RES, (y-5)*utils.RES, False )

	px = 0
	cant_click_l = 0
	cant_click_r = 0
    	while salir == 0:

	    	# Pump GTK messages.
		while gtk.events_pending():
			gtk.main_iteration()
			
		for eventos in pygame.event.get():
			if eventos.type == QUIT:
				sys.exit(0)
			elif eventos.type == pygame.VIDEORESIZE:
			   pygame.display.set_mode(eventos.size, pygame.RESIZABLE)	
			elif eventos.type == MOUSEBUTTONDOWN:
				x, y = pygame.mouse.get_pos()
				if btn_adelante.rect.collidepoint(x, y):
					salir = 5
					btn_adelante.sonido.play()	
				elif btn_atras.rect.collidepoint(x, y):
					salir = 3
					btn_atras.sonido.play()	
				#print str(x) + str(y)
				'''if pixell_rect.collidepoint(x, y) or pixell2_rect.collidepoint(x, y):
					cant_click_r = 0
					cant_click_l = cant_click_l + 1 
					if cant_click_l > 4 :
						cant_click_l = 0

				elif pixelt_rect.collidepoint(x, y) or pixelt2_rect.collidepoint(x, y):
					cant_click_l = 0
					cant_click_r = cant_click_r + 1 
					if cant_click_r > 5 :
						cant_click_r = 0'''

		# Realiza la animacion del texto				

		screen.blit(background_image, (0, 0))
		screen.blit(clase2, clase2_rect)
		screen.blit(titulo1, titulo1_rect)
		screen.blit(titulo2, titulo2_rect)

		screen.blit(temas, temas_rect)	

		px = px + 1
		if px <= 20 :
			screen.blit(p1a.image, p1a.rect)
			screen.blit(p2a.image, p2a.rect)
			screen.blit(p3a.image, p3a.rect)
			screen.blit(p4a.image, p4a.rect)
			screen.blit(p5a.image, p5a.rect)
		elif px <= 40 :
			screen.blit(p1b.image, p1b.rect)
			screen.blit(p2b.image, p2b.rect)
			screen.blit(p3b.image, p3b.rect)
			screen.blit(p4b.image, p4b.rect)
			screen.blit(p5b.image, p5b.rect)

		else:
			px = 0

		screen.blit(btn_adelante.image, btn_adelante.rect)
		screen.blit(btn_atras.image, btn_atras.rect)		
		screen.blit(cursor_picture, pygame.mouse.get_pos())
		pygame.display.flip()

		# Try to stay at 30 FPS
		clock.tick(30)

	return salir


# ./TestGame.py 
def main():
	
	pygame.init()
	screen = pygame.display.set_mode((int(800*utils.RES), int(520*utils.RES)), pygame.RESIZABLE) #pygame.display.get_surface() #

	# Fake a Sugar cursor for the pyGame canvas area
	pygame.mouse.set_cursor((8,8),(0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0))
	cursor_picture = pygame.image.load('images/standardcursor.png')
	cursor_picture.convert_alpha() 
	clock = pygame.time.Clock()
	dibujar(screen,cursor_picture,clock)

if __name__ == '__main__':
   main()
